<?php
/**
 * @method-name : quickly login page or register page.
 * @author      : stephen.mo <stephen.mo@achievo.com>
 * @date        : Dec 9,2010
 */
require_once "TVB/OAuth/common.inc.php";
#ini_set("display_errors","on");

//params
$redirect_url     = (isset($_REQUEST['redirect_to'])) ? $_REQUEST['redirect_to'] : NULL;
$lang             = (isset($_REQUEST['lang'])) ? OAuthUtils::chkLang($_REQUEST['lang']) : OAuthConfig::DEFAULT_SUPPORT_LANG;
$third_name       = (isset($_REQUEST['pg'])) ? $_REQUEST['pg'] : NULL;
$reback_url       = (isset($_REQUEST['reback_url'])) ? $_REQUEST['reback_url'] : NULL;
$network_type     = (isset($_REQUEST['ntype']) && !empty($third_name) && strtolower($third_name)==OAuthModelConfig::DEFAULT_GATEWAY_OF_CSL) ? $_REQUEST['ntype'] : NULL;

//set path
$base_server_path = OAuthConfig::OAuthDomainUrl($_SERVER);
$ajax_url         = $base_server_path.OAuthConfig::DEFAULT_AJAX_URL;
$header_url       = $base_server_path.OAuthConfig::DEFAULT_HEADER_URL;
$jqtouch_url      = $base_server_path.OAuthModelConfig::DEFAULT_MOBILE_TEMPLATE;
$login_self       = OAuthConfig::OAuthGetRestUrl($_SERVER);
$forget_pwd_url   = OAuthConfig::MEMBER_FORGET_URL.'?lang='.$lang.'&reback_url='.urlencode($login_self);
$goback_url       = $redirect_url;
$plan_details_url = $base_server_path.OAuthConfig::DEFAULT_SUPPORT_PLAN_DETAILS;
$success_url      = $plan_details_url.'?lang='.$lang.'&pg='.$third_name.'&call_back='.urlencode($redirect_url);

//this page can't get the login_id ,so will crumb a string not include the login_id.
$network_str      = (!empty($network_type)) ? '&ntype='.$network_type : NULL;
$params = array();
$params['exT']      = time()+OAuthModelConfig::THIRD_PAYMENT_EXPIRE_TIME; //timestamp.
$params['randN']    = rand();
$params['clientIp'] = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
$crumb_string = OAuthUtils::genCrumbString($params,1);
$success_url  = $success_url.'&randN='.$params['randN'].'&exT='.$params['exT'].'&crumbS='.$crumb_string.'&pFlag=NOT'.$network_str;

//if other page has using this page to sign-in then redirect to reback_url ,if success
if (!empty($reback_url)) $success_url = $reback_url;

//set page info
$sign_in_page      = OPI::$login_page_info[$lang];
$register_page     = OPI::$register_page_info[$lang];
$forget_pass_page  = OPI::$forget_password[$lang];
$payment_buttons   = OPI::$payment_button_info[$lang];

//template setting.
$form = array();
$using_real_env    = OAuthModelConfig::USING_TEMPLATE_ON_REAL_ENV; 
$page              = OAuthModelConfig::M_PAGE_OF_PLAN_SIGNIN;
$microtime         = OAuthModelConfig::getMicroFloatTime(); 
//$details_vars      = OAuthUtils::getPaymentConfDetail($third_name);
//$iphone_msisdn_url = $details_vars['get_msisdn_url'];

$form['lang']               = $lang;
$form['title']              = $sign_in_page['page_title'];
$form['login_title']        = $sign_in_page['page_title'];
//login div vars.
$form['login_notes']        = $sign_in_page['qlogin_notes'][$third_name];
$form['login_id']           = $sign_in_page['login_id'];
$form['password']           = $sign_in_page['password'];
//reg div vars.
$form['reg_title']          = $register_page['reg_title'];
$form['reg_email']          = array('title'=>$register_page['email'],'note'=>$register_page['email_msg']);
$form['reg_pwd']            = array('title'=>$register_page['password'],'note'=>$register_page['password_msg']);
$form['reg_repwd']          = array('title'=>$register_page['repassword'],'note'=>NULL);
$form['reg_captcha']        = array('title'=>$register_page['captcha'],'note'=>$register_page['captcha_note']);
$form['forget']             = array('title'=>$forget_pass_page['fpassword_title'],'link'=>$forget_pwd_url);
//form vars.
$form['action']             = array('login'=>NULL,'reg'=>NULL);
$form['ajax_url']           = $ajax_url;
$form['method']             = 'POST';
$form['success_url']        = $success_url;
$form['items']              = array('login'=>'quickSignIn','reg'=>'quickRegister');
$form['microtime']          = $microtime;
$form['hidden']             = array('pg'=>$third_name,);

//buttons vars.
$form['button']['cancel']   = array('value'=>$payment_buttons['back'], 'link'=>$goback_url);
$form['button']['signin']   = array('value'=>$payment_buttons['login'], 'link'=>null);
$form['button']['register'] = array('value'=>$payment_buttons['register'],'link'=>NULL);

//include this template for page.
include "..".OAuthModelConfig::DEFAULT_MOBILE_TEMPLATE.OAuthModelConfig::$mobile_teplate_page[$page];
?>
